package com.bjc.sdx.fragment;

import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import androidx.fragment.app.Fragment;

import com.bjc.sdx.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class Fragment3 extends Fragment {
    ListView lv_man;
    private final String TAG = "Fragment3---->button---->";
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment3, container,false);
        lv_man = view.findViewById(R.id.lv_man);
        ArrayList<Map<String, Object>> arrayList = new ArrayList<Map<String,Object>>();
        //new了一个Arraylist数组包含map集合
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        //new了一个map集合编写key value
        hashMap=new HashMap<String, Object>();
        //简写用上面hashMap的对象再新建一个map集合,赋值,添加到arrayList集合中
        hashMap.put("icom", R.drawable.apple);
        hashMap.put("name","美食--2");
        hashMap.put("content","内容");
        arrayList.add(hashMap);

        hashMap=new HashMap<String, Object>();
        hashMap.put("icom", R.drawable.gril);
        hashMap.put("name","美食--3");
        hashMap.put("content","内容");
        arrayList.add(hashMap);

        hashMap=new HashMap<String, Object>();
        hashMap.put("icom", R.drawable.banana);
        hashMap.put("name","美食--4");
        hashMap.put("content","内容");
        arrayList.add(hashMap);

        hashMap=new HashMap<String, Object>();
        hashMap.put("icom", R.drawable.strawberry);
        hashMap.put("name","美食--5");
        hashMap.put("content","内容");
        arrayList.add(hashMap);

        hashMap=new HashMap<String, Object>();
        hashMap.put("icom", R.drawable.ic_baseline_star_24);
        hashMap.put("name","美食--6");
        hashMap.put("content","内容");
        arrayList.add(hashMap);

        hashMap=new HashMap<String, Object>();
        hashMap.put("icom", R.drawable.baidu_cloud);
        hashMap.put("name","美食--7");
        hashMap.put("content","内容");
        arrayList.add(hashMap);

        arrayList.add(hashMap);
        //arrayList集合里面有许多个map集合,map集合中有许多的数据
//      Map对象中的key的数组,用于得到对应的value
        String from[]={"icom","name","content"};//定义from代表map里面的key值
//      item布局文件中的子View的id的数组
        int [] to ={R.id.imageView1,R.id.tv_item_name,R.id.tv_item_content,};
        //定义to代表布局控件
//      准备SimpleA
        SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), arrayList,
                R.layout.lv_child, from, to);
        //加载包含to的控件视图(不是视图id),from是通过key获取了value值,
//      to是把value赋给了布局中的控件
        lv_man.setAdapter(simpleAdapter);
//      设置适配器


        View view1 = inflater.inflate(R.layout.lv_child, container,false);
        Button button = view1.findViewById(R.id.shure_true_or_false);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "onClick: 你点击了button");
                Drawable darwble = v.getBackground();
                if (darwble.equals(getResources().getDrawable(R.drawable.not_shure))){
                    v.setBackground(getResources().getDrawable(R.drawable.shure));
                } else {
                    v.setBackground(getResources().getDrawable(R.drawable.not_shure));
                }
            }
        });
        return view;
    }

}
